package org.sqlproc.engine.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;

import org.hibernate.annotations.ForeignKey;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

/**
*
* Entity representing Book.
*/
@Entity
@Table(name = "BOOK")
@PrimaryKeyJoinColumn(name = "MEDIA")
@ForeignKey(name = "FK_BOOK_MEDIA")
//@EntityListeners({org.hibernate.validator.event.JPAValidateListener.class
//})
public class Book extends Media {
    @Column(name = "ISBN", nullable = false, length = 20, unique = true)
    @Length(max = 20)
    @NotEmpty
    private String isbn;

    public Book() {
    }

    public Book(String title, String isbn) {
        super(title);
//        Validate.notNull(isbn);
        this.isbn = isbn;
    }

    public String getIsbn() {
        return isbn;
    }

    /**
     * This method is used by equals and hashCode.
     * @return {@link #getIsbn}
     */
    public Object getKey() {
        return getIsbn();
    }
}
